package com.polito.mad.bikeponyapp.util;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.polito.mad.bikeponyapp.R;

public class DialogCreator {

	public static AlertDialog createAlertDialog(Context context,String message,String title)
	{
			AlertDialog.Builder builder = createDefaultAlertDialogBuilder(context, message, title);
	        return builder.create();
	}
	
	public static AlertDialog.Builder createDefaultAlertDialogBuilder(Context context,String message,String title)
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
		
        View view = inflater.inflate(R.layout.custom_dialog_layout, null);
        TextView titleTextView = (TextView)view.findViewById(R.id.dialog_title);
        TextView messageTextView = (TextView)view.findViewById(R.id.dialog_message);
        titleTextView.setText(title);
        messageTextView.setText(message);
        builder.setView(view);
        return builder;
	}
	public static AlertDialog createConfirmAlertDialog(Context context ,String message,String title,DialogInterface.OnClickListener positiveClickListener,DialogInterface.OnClickListener negativeClickListener)
	{
		
		AlertDialog.Builder builder = createDefaultAlertDialogBuilder(context, message, title);
        if(positiveClickListener!=null)
        	builder.setPositiveButton(android.R.string.ok, positiveClickListener);
        if(negativeClickListener!=null)
        	builder.setNegativeButton(android.R.string.no, negativeClickListener);
        return builder.create();
	}
	public static AlertDialog createNewTasksAlertDialog(Context context ,String message,String title,List<String[]>newTasks)
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
		
        View view = inflater.inflate(R.layout.custom_new_tasks_dialog_layout, null);
        TextView titleTextView = (TextView)view.findViewById(R.id.dialog_title);
        TextView messageTextView = (TextView)view.findViewById(R.id.dialog_message);
        titleTextView.setText(title);
        messageTextView.setText(message);
        ListView lv = (ListView) view.findViewById(R.id.newTasksList);
        
        lv.setAdapter(new newTasksListAdapter(context, newTasks));
        builder.setView(view);
        return builder.create();
	}
}
